const express = require('express')
const route = express.Router();
const adminModel = require("../db/model/adminModel")
const isLoginMiddle = require("../middleware/isLoginMiddle");

route.delete("/deleteAdmin", isLoginMiddle,async (req, res) => {
  const {
    adminName
  } = req.query
  // console.log(req.query)
  try {
    const deleteResult = await adminModel.deleteOne({adminName})
    if (deleteResult.deletedCount > 0) {
      return res.send(
        {
          code: 10000,
          msg: "管理员删除成功！！！！",
          data: null
        }
      )
    }
    res.send({
      code: 10001,
      msg: "管理员删除失败！！！！",
      data: null
    })

  } catch (e) {
    console.log("删除管理员失败" + e.message);
    res.send({
      code: 10001,
      msg: e.message + "删除失败",
      data: null
    })
  }

})
module.exports = route;